<template>
	<view>
		<u-tabs :list="tabList" :is-scroll="false" :current="currTab" @change="e=>currTab=e"></u-tabs>
		<view v-if="false" class="row-around bg-white" style="padding: 20rpx 0;">
			<view class="row" @tap="toggleSort('team')">
				<view>
					团队排序
				</view>
				<view>
					<trigonometry direction="up" size="small" :color="sort.team == 1 ? 'var(--primary-color)' : '#333'">
					</trigonometry>
					<trigonometry size="small" :color="sort.team == 2 ? 'var(--primary-color)' : '#333'">
					</trigonometry>
				</view>
			</view>
			<view class="row" @tap="toggleSort('price')">
				<view>
					金额排序
				</view>
				<view>
					<trigonometry direction="up" size="small"
						:color="sort.price == 1 ? 'var(--primary-color)' : '#333'">
					</trigonometry>
					<trigonometry size="small" :color="sort.price == 2 ? 'var(--primary-color)' : '#333'">
					</trigonometry>
				</view>
			</view>
			<view class="row" @tap="toggleSort('order')">
				<view>
					订单排序
				</view>
				<view>
					<trigonometry direction="up" size="small"
						:color="sort.order == 1 ? 'var(--primary-color)' : '#333'">
					</trigonometry>
					<trigonometry size="small" :color="sort.order == 2 ? 'var(--primary-color)' : '#333'">
					</trigonometry>
				</view>
			</view>
		</view>
		<view style="padding: 0 20rpx;">
			<view class="bg-white mt20" style="border-radius: 24rpx;padding: 20rpx 30rpx;box-sizing: border-box;"
				v-for="item in dataList" :key="item.id">
				<view class="row" style="gap:20rpx">
					<image :src="item.logo" mode="aspectFill" style="width: 200rpx;height: 200rpx"></image>
					<view class="column" style="gap: 30rpx;">
						<view class="xl">
							{{item.name}}
							<text style="color: #FF2C3C;font-size: 24rpx;">({{item.tname}})</text>
						</view>
						<view>
							<image src="@/static/images/icon_7.png" mode="widthFix" class="icon"></image>
							<text class="text">{{item.tel}}</text>
							<image src="@/static/images/icon_6.png" mode="widthFix" class="icon"
								@click="callPhone(item.tel)"></image>
						</view>
						<view class="lighter">{{item.create_time}}</view>
					</view>
				</view>
				<view class="row-between mt30" style="background-color: #fcf9f3;padding: 20rpx 30rpx;">
					<view class="column-center">
						<view class="muted">
							代理下属
						</view>
						<view class="xxl mt10" style="color: #a16624;">
							{{item.agent_num}}
						</view>
					</view>
					<view class="column-center">
						<view class="muted">
							单总数(单)<u-icon name="question-circle" @click="toast('下属团队的订单统计')"></u-icon>
						</view>
						<view class="xxl mt10" style="color: #a16624;">
							{{item.order_num}}
						</view>
					</view>
					<view class="column-center">
						<view class="muted">
							营收总额(元)<u-icon name="question-circle" @click="toast('下属团队的营业额统计')"></u-icon>
						</view>
						<view class="xxl mt10" style="color: #a16624;">
							{{item.order_money}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<loading-footer :status="status"></loading-footer>
	</view>
</template>

<script>
	const tabList = [{
		name: "全部",
		id: 0,
	}, {
		name: "一级团队",
		id: 1,
	}, {
		name: "二级团队",
		id: 2,
	}]
	import {
		getMySteamList
	} from '../../../api/user';
	import {
		loadingFun
	} from '../../../utils/tools';
	import {
		loadingType
	} from '../../../utils/type';
	export default {
		data() {
			return {
				tabList: tabList,
				currTab: 0,

				page: 1,
				status: loadingType.LOADING,
				dataList: [],

				sort: {
					price: 0,
					team: 0,
					order: 0,
				}
			};
		},
		onLoad() {
			this.getList();
		},
		onReachBottom() {
			this.getList();
		},
		watch: {
			currTab() {
				this.clear();
				this.getList();
			}
		},
		methods: {
			/**
			 * 拨打电话
			 * @param tel 电话
			 */
			callPhone(tel) {
				uni.makePhoneCall({
					phoneNumber: tel
				})
			},
			toast(str) {
				this.$toast({
					title: str
				})
			},
			clear() {
				this.page = 1;
				this.status = loadingType.LOADING;
				this.dataList = [];
			},
			async getList() {
				const data = await loadingFun(getMySteamList, this.page, this.dataList, this.status, {
					status: this.tabList[this.currTab].id
				})
				if (data) {
					this.page = data.page;
					this.status = data.status;
					this.dataList = data.dataList
				}
			},
			toggleSort(prop) {
				let val = this.sort[prop];
				if (val < 2) {
					val++;
				} else if (val == 2) {
					val = 0
				}
				this.sort[prop] = val;
			}
		}
	}
</script>

<style lang="less">

</style>